//
//  DailyScrum.swift
//  codelabs
//
//  Created by 雷雷 on 25/05/2025.
//

import Foundation
import ThemeKit
import SwiftData


@Model
class DailyScrum:Identifiable{
    var id:UUID
    var title:String
    
    @Relationship(deleteRule:.cascade,inverse: \Attendee.scrum)
    var attendees:[Attendee] = []
    
    var lengthInMinutes:Int
    var lengthInMinutesAsDouble: Double {
        get {
            Double(lengthInMinutes)
        }
        set {
            lengthInMinutes = Int(newValue)
        }
    }
    var theme:Theme
    
    @Relationship(deleteRule:.cascade, inverse: \ScrumHistory.scrum)
    var history:[ScrumHistory] = []
    
    init(id:UUID = UUID(), title:String="", attendees:[String] = [], lengthInMinutes:Int=5,theme:Theme,){
        self.id=id
        self.title=title
        self.attendees=attendees.map{Attendee(name:$0)}
        self.lengthInMinutes=lengthInMinutes
        self.theme=theme
    }
    
    init(_ from:DailyScrum){
        self.id=from.id
        self.title=from.title
        self.attendees=from.attendees
        self.lengthInMinutes=from.lengthInMinutes
        self.theme=from.theme
        self.history=from.history
    }
    
}
